<?php
/**
 * 模板适配器
 * @author Yuwei(yuwei1122@gmail.com)
 *
 */
class BluePhp_Library_Template_Adapter
{
	/**
	 * 构造函数
	 */
	public function __construct()
	{
		$dir = array(TP_TEMPORARY_DIR,TP_COMPILE_DIR,TP_CACHE_DIR,TP_PLUGINS_DIR);
		foreach ($dir as $one)
			if(!is_dir($one))
				mkdir($one) or die('目录创建失败，请检查权限');
		/**
		 * 引入类文件
		 */
		require_once 'Smarty'.DIRECTORY_SEPARATOR.'libs'.DIRECTORY_SEPARATOR.'Smarty.class.php';
		
		/**
		 * 配置信息
		 */
		$this->_smarty = new Smarty();
		$this->_smarty->template_dir = TP_DIR;
		$this->_smarty->compile_dir = TP_COMPILE_DIR;
		$this->_smarty->left_delimiter = TP_LEFT_DELIMITER;
		$this->_smarty->right_delimiter = TP_RIGHT_DELIMITER;
		$this->_smarty->debugging = TP_DEGUGGING;
		$this->_smarty->caching = TP_CACHEING;
		$this->_smarty->cache_dir = TP_CACHE_DIR;
		$this->_smarty->cache_lifetime = TP_CACHE_LIFETIME;
		$this->_smarty->plugins_dir = TP_PLUGINS_DIR;
	}
	
	/**
	 * 模板类
	 * @var unknown_type
	 */
	protected $_smarty;
	
	/**
	 * 数据设置
	 * @param unknown_type $tpl_var
	 * @param unknown_type $value
	 */
	public function assign($tpl_var,$value)
	{
		$this->_smarty->assign($tpl_var,$value);
	}
	
	/**
	 * 展示
	 *
	 * @param unknown_type $template
	 */
	public function display($template,$option='')
	{
		/**
		 * 数据设置
		 */
		if($option && is_array($option))
			foreach ($option as $key => $value)
				$this->_smarty->assign($key,$value);
		
		/**
		 * 公共配置
		 */
		$this->_smarty->assign('_IMAGE_','.'.DIRECTORY_SEPARATOR.'image'.DIRECTORY_SEPARATOR);//图片路径
		$this->_smarty->assign('_CSS_','.'.DIRECTORY_SEPARATOR.'css'.DIRECTORY_SEPARATOR);//css路径
		$this->_smarty->assign('_JS_','.'.DIRECTORY_SEPARATOR.'js'.DIRECTORY_SEPARATOR);//js路径
		
		/**
		 * 页面展示
		 */
		$this->_smarty->display($template);
		die();
	}
}
?>